package com.ziyia.navigationview;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.google.android.material.appbar.CollapsingToolbarLayout;

public class ElementActivity extends AppCompatActivity {

    public static final String ELEMENT_NAME = "ename";
    public static final String ELEMENT_IMAGE_ID = "eimageid";
    private static final String TAG = ElementActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_element);
        Intent intent = getIntent();
        String name = intent.getStringExtra(ELEMENT_NAME) != null ? intent.getStringExtra(ELEMENT_NAME) : "";
        String imageId = intent.getStringExtra(ELEMENT_IMAGE_ID) != null ? intent.getStringExtra(ELEMENT_IMAGE_ID) : "";
        String objStr = intent.getStringExtra("obj") != null ? intent.getStringExtra("obj") : "没有接收到数据";
        Log.d(TAG, "name = " + name);
        Log.d(TAG, "imageId = " + imageId);

//
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsingToolbar);
        collapsingToolbarLayout.setTitle(name);

        TextView elementContentText = findViewById(R.id.ElementContentText);
        elementContentText.setText(objStr);


    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}